package Strategy;

//import Interface.IChat;
import ObjectFileOptions.ObjectFile;
import Packets.pkValue;
//import StaticClass.ArrSocket;
import Thread.ThreadChat;
//import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
//import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Oho
 */
public class A_Interface {
    //kiem tra xem co ton tai jframe nao co chat hok 

    SIPack part;
    ThreadChat tc;

    public A_Interface(ThreadChat tc) {
        this.tc = tc;
    }

    public void setSIPart(int type) {
        if (type == 1) {
            part = new SI_Chat();
        }
        if (type == 2) {
            // part = new SI_SendFile();
            //viet ham trong nay de goi lai dong thoi tao class moi implement lai 2 phuong thuc cua SIPart
        }
    }

    public void Check(pkValue pk, String str, String value, ObjectInputStream in, ObjectOutputStream out) {
        //   JFrame f = new IChat()instanceof IChat;
        //la loai nao ? 
        
        setSIPart(1);
        JFrame temp = part.check(tc);//lay jframe dang chat
        if (temp != null) {

            try {

                if (value.compareTo("READ") == 0) {
                    str = "Client ";
                    //in = new ObjectInputStream(sk.getInputStream());
                    pk = (pkValue) in.readObject();
                }
                if (value.compareTo("WRITE") == 0) {
                    str = "Server ";

                    //   out = new ObjectOutputStream(sk.getOutputStream());
                    out.writeObject(pk);
                    out.flush();
                }
                //neu la chat 
                //pk goi tin 
                //temp cua so 
                //str chuoi client/server
                part.ConvertPackage(pk, temp, str);
            } catch (IOException ex) {
                Logger.getLogger(ObjectFile.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(ObjectFile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }




    }
}
